// Copyright 2019 The rhyme_lph Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Q [author] rhyme_lph
// J [email]  rhymelph@gmail.com
// l [github] https://github.com/rhymelph

import 'package:base_plugin/base_plugin.dart';
import 'package:finance_app/generated/l10n.dart';
import 'package:finance_app/src/common/app_colors.dart';
import 'package:finance_app/src/common/app_spaces.dart';
import 'package:finance_app/src/common/config.dart';
import 'package:finance_app/src/provider/login/request_free_demo_provider.dart';
import 'package:finance_app/src/router_gen/router_meta.dart';
import 'package:finance_app/src/widgets/button/normal_button.dart';
import 'package:finance_app/src/widgets/common_app_bar.dart';
import 'package:finance_app/src/widgets/input/input_field.dart';
import 'package:finance_app/src/widgets/input/phone_number_input_field.dart';
import 'package:finance_app/src/widgets/select/normal_check_box.dart';
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';

export 'package:finance_app/src/entities/company_entity.dart';

@RouterMeta(paramName: "requestFreeDemoPage")
class RequestFreeDemoPage extends StatefulWidget {
  const RequestFreeDemoPage({Key key}) : super(key: key);

  @override
  _RequestFreeDemoPageState createState() => _RequestFreeDemoPageState();
}

class _RequestFreeDemoPageState extends State<RequestFreeDemoPage>
    with PagePresenter<RequestFreeDemoPage, RequestFreeDemoProvider> {
  @override
  void initState() {
    super.initState();
  }

  @override
  PreferredSizeWidget get appBar =>
      getDefaultAppBar(title: S.current.request_free_demo);

  TextStyle style = TextStyle(
      color: aceBlackColor, fontWeight: FontWeight.w700, fontSize: 16);

  @override
  Widget get buildWidget => ColoredBox(
        color: Colors.white,
        child: ListView(
          padding: EdgeInsets.symmetric(horizontal: 25),
          children: [
            AppSpaces.h20,
            Text(S.current.name, style: style),
            AppSpaces.h10,
            InputField(
              margin: EdgeInsets.zero,
              controller: provider.nameController,
              hint: S.current.name,
              isBlue: true,
            ),
            AppSpaces.h20,
            Text(S.current.mobile_number, style: style),
            AppSpaces.h10,
            listBuilder<String>(
              selector: (_, __) => __.countryCode,
              builder: (BuildContext context, String value, Widget child) =>
                  PhoneNumberInputField(
                defaultCountryCode: value,
                horizontalPadding: 0,
                isBlue: true,
                controller: provider.phoneNumberController,
                countryCodeCallback: provider.onChangeCountryCode,
              ),
            ),
            AppSpaces.h20,
            Text(S.current.email, style: style),
            AppSpaces.h10,
            InputField(
              margin: EdgeInsets.zero,
              controller: provider.emailController,
              hint: S.current.email,
              isBlue: true,
            ),
            AppSpaces.h20,
            Text(S.current.important_notice, style: style),
            AppSpaces.h10,
            Text(
              S.current
                  .this_is_a_request_for_free_demo_guest_id_we_will_not_ask_for_any_payment_nor_credit_card_information_from_you,
              style: TextStyle(color: aceBlackColor, height: 1.5, fontSize: 16),
            ),
            AppSpaces.h35,
            PressedOpacityButton(
              onPressed: provider.onChangePrivacyCheck,
              child: Row(
                children: [
                  listBuilder<bool>(
                    selector: (_, __) => __.isCheckPrivacyPolicy,
                    builder: (BuildContext context, bool value, Widget child) =>
                        NormalCheckBox(
                      isSelect: value,
                      title: S.current.accept + ' ',
                      minWidth: 0,
                      fontSize: 16,
                    ),
                  ),
                  PressedOpacityButton(
                    onPressed: () {
                      launch(Config.privacyPolicyUrl);
                    },
                    child: Text(
                      S.current.privacy_policy,
                      style: TextStyle(
                        fontWeight: FontWeight.bold,
                        fontSize: 16,
                        color: aceBlueColor,
                        height: 1,
                      ),
                    ),
                  ),
                ],
              ),
            ),
            AppSpaces.h35,
            listBuilder<bool>(
                builder: (BuildContext context, bool value, Widget child) =>
                    NormalButton(
                      title: S.current.submit,
                      onTap: value == true ? provider.onSubmit : null,
                    ),
                selector: (_, __) => __.enable && __.isCheckPrivacyPolicy)
          ],
        ),
      );
}
